package com.ljm.sys.org.controller;

import com.ljm.common.dto.BaseResult;
import com.ljm.common.util.ResultUtil;
import com.ljm.security.util.UserUtil;
import com.ljm.sys.org.api.SysOrgDepartApi;
import com.ljm.sys.org.dto.SysOrgDepartDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
    * 部门表 前端控制器
    * </p>
 *
 * @author ming
 * @since 2019-04-12
 */
@Api(description="部门信息",tags = {"部门信息"})
@RestController
@RequestMapping("/org/sysOrgDepart")
public class SysOrgDepartController {

    /**
    * 部门表接口
    */
    @Resource
    private SysOrgDepartApi iSysOrgDepartApi;

    @ApiOperation(value="保存部门表")
    @PostMapping(value = "/save")
    public BaseResult save(@ApiParam(value="部门表") @RequestBody SysOrgDepartDto dto){
        iSysOrgDepartApi.saveData(dto, UserUtil.getCurUser());
        return ResultUtil.success();
    }

    @ApiOperation(value="删除部门表")
    @PostMapping(value = "/del")
    public BaseResult del(@ApiParam(value="主键") @RequestBody List<Long> ids){
        iSysOrgDepartApi.delData(ids);
        return ResultUtil.success();
    }

    @ApiOperation(value="获取部门表")
    @GetMapping(value = "/getById")
    public BaseResult getById(@ApiParam(value="主键") @RequestParam Long id){
        return ResultUtil.successData(iSysOrgDepartApi.getDataById(id));
    }

    @ApiOperation(value="分页获取部门表")
    @GetMapping(value = "/getByPage")
    public BaseResult getByPage(
            @ApiParam(value="部门名称") @RequestParam String deptName,
            @ApiParam(value="部门类型") @RequestParam String type,
            @ApiParam(value="页码") @RequestParam Integer pageNo,
            @ApiParam(value="页大小") @RequestParam Integer pageSize){
        return ResultUtil.successData(iSysOrgDepartApi.getDataByPage(deptName,type,pageNo,pageSize));
    }

    @ApiOperation(value="获取子部门表")
    @GetMapping(value = "/getChildDept")
    public BaseResult getChildDept(@ApiParam(value="部门id") @RequestParam Long parentId){
        return ResultUtil.successData(iSysOrgDepartApi.getChildDept(parentId));
    }

    @ApiOperation(value="获取机构下所有部门")
    @GetMapping(value = "/getAllDeptByOrgId")
    public BaseResult getAllDeptByOrgId(){
        return ResultUtil.successData(iSysOrgDepartApi.getAllDeptByOrgId(UserUtil.getCurUser().getOrgId()));
    }

    @ApiOperation(value="获取顶级部门")
    @GetMapping(value = "/getRootDept")
    public BaseResult getRootDept(){
        return ResultUtil.successData(iSysOrgDepartApi.getRootDept(UserUtil.getCurUser().getOrgId()));
    }

}
